package cn.xiaopengstack.domain.activity.service.trialcal.node;

import cn.xiaopengstack.domain.activity.model.entity.MarketProductEntity;
import cn.xiaopengstack.domain.activity.model.entity.TrialCalculateEntity;
import cn.xiaopengstack.domain.activity.service.trialcal.AbstractGroupBuyMarketSupport;
import cn.xiaopengstack.domain.activity.service.trialcal.factory.DefaultActivityStrategyFactory;
import cn.xiaopengstack.types.enums.ResponseCode;
import cn.xiaopengstack.types.exception.AppException;
import cn.xiaopengstack.types.framework.strategy.tree.StrategyHandler;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author jiangyangang
 */
@Component
@Slf4j
public class ErrorNode extends AbstractGroupBuyMarketSupport {


    @Override
    protected TrialCalculateEntity doApply(MarketProductEntity param, DefaultActivityStrategyFactory.DynamicContext dynamicContext) throws Exception {
        log.info("拼团商品查询试算服务-NoMarketNode userId:{} requestParameter:{}", param.getUserId(), JSONObject.toJSONString(param));

        // 无营销配置
        if (null == dynamicContext.getGroupBuyActivityDiscountVO() || null == dynamicContext.getSkuVO()) {
            log.info("商品无拼团营销配置 {}", param.getGoodsId());
            throw new AppException(ResponseCode.INVALID_ACTIVITY.getCode(), ResponseCode.INVALID_ACTIVITY.getInfo());
        }

        return TrialCalculateEntity.builder().build();

    }

    @Override
    public StrategyHandler<MarketProductEntity, DefaultActivityStrategyFactory.DynamicContext, TrialCalculateEntity> get(MarketProductEntity param, DefaultActivityStrategyFactory.DynamicContext dynamicContext) throws Exception {
        return defaultStrategyHandler;
    }
}
